/*
 * @Author: Kaze 3243442830@qq.com
 * @Date: 2025-04-07 14:23:37
 * @LastEditors: Kaze 3243442830@qq.com
 * @LastEditTime: 2025-04-09 13:45:05
 * @FilePath: \vue-position-master\src\stores\modules\map.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from 'pinia'

export const useMapStore = defineStore('map', {
  state: () => ({
    mapInitialized: false,
    currentIs2D: true,
    isRotating: false,
    showKeyboardTips: true,
    mapInstance: null,
    map3dInstance: null,
    sourceFeatures: null,
    lineString: null,
    currentView: {
      center: [116.397428, 39.90923],
      zoom: 12
    },
    keyState: {
      forward: false,
      backward: false,
      left: false,
      right: false,
      up: false,
      down: false,
      speedUp: false,
      speedDown: false
    },
    movementSpeed: 10,
    rotationSpeed: 0.02,
    rotationAnimation: null
  }),

  getters: {
    isMapReady: (state) => state.mapInitialized,
    is3DMode: (state) => !state.currentIs2D,
    hasMapInstance: (state) => state.mapInstance !== null,
    hasMap3DInstance: (state) => state.map3dInstance !== null
  },

  actions: {
    setMapInstance(map) {
      this.mapInstance = map
    },
    
    setMap3DInstance(map3d) {
      this.map3dInstance = map3d
    },
    
    setMapInitialized(status) {
      this.mapInitialized = status
    },
    
    toggleView() {
      this.currentIs2D = !this.currentIs2D
    },
    
    setRotating(status) {
      this.isRotating = status
    },
    
    updateCurrentView(center, zoom) {
      this.currentView = { center, zoom }
    },
    
    resetView() {
      this.currentView = {
        center: [116.397428, 39.90923],
        zoom: 12
      }
    },

    setKeyState(key, value) {
      this.keyState[key] = value
    },

    updateMovementSpeed(delta) {
      this.movementSpeed = Math.max(1, Math.min(50, this.movementSpeed + delta))
    },

    updateRotationSpeed(delta) {
      this.rotationSpeed = Math.max(0.005, Math.min(0.1, this.rotationSpeed + delta))
    },

    setRotationAnimation(animation) {
      this.rotationAnimation = animation
    },

    setSourceFeatures(features) {
      this.sourceFeatures = features
    },

    setLineString(line) {
      this.lineString = line
    }
  }
}) 